package com.ellecity06.cwhiskymall.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.response.ConsumerRecordResponse
import com.ellecity06.cwhiskymall.databinding.ItemReceiveRecordShop9000Binding
import java.text.SimpleDateFormat
import java.util.Date

/**
 * @author ellecity06
 * @time 2024/10/29 18:57
 * @des
 */
class Shop9000ReceiveRecordAdapter :
    BaseAdapter<ConsumerRecordResponse.ReceiveRecord, ItemReceiveRecordShop9000Binding>() {
    @SuppressLint("SimpleDateFormat")
    private val dataformat = SimpleDateFormat("yyy-MM-dd")
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemReceiveRecordShop9000Binding {
        return ItemReceiveRecordShop9000Binding.inflate(layoutInflater, parent, false)
    }

    override fun convert(
        binding: ItemReceiveRecordShop9000Binding,
        position: Int,
        item: ConsumerRecordResponse.ReceiveRecord
    ) {
        binding.tvDays.text = "第${position + 1}天"
        if (item.receiveStatus == -1) {
            // 待领取
            binding.root.setBackgroundResource(R.drawable.shape_shop9000_state2)
            binding.tvDays.setBackgroundColor(Color.parseColor("#FFB9D7"))
            binding.tvAction.setTextColor(Color.parseColor("#9B76AD"))
            binding.ivGold.setImageResource(R.mipmap.icon_gold)
            binding.tvAction.setTextColor(Color.parseColor("#FFFFFF"))
            binding.tvAction.text = "待领取"
        } else if (item.receiveStatus == 1) {
            binding.root.setBackgroundResource(R.drawable.shape_shop9000_state0)
            binding.tvDays.setBackgroundColor(Color.parseColor("#FF82B8"))
            binding.tvAction.setTextColor(Color.parseColor("#FF82B8"))
            binding.ivGold.setImageResource(R.mipmap.icon_shop9000_true)
            binding.tvAction.text = "已领"
        } else {
            if (item.receiveTime!=null&&item.receiveTime.isNotEmpty() && dataformat.parse(item.receiveTime!!).before(dataformat.parse(dataformat.format(Date())))) {
                // 说明错过时间 未领取
                binding.root.setBackgroundResource(R.drawable.shape_shop9000_state1)
                binding.tvDays.setBackgroundColor(Color.parseColor("#D9D9D9"))
                binding.tvAction.setTextColor(Color.parseColor("#D3D3D3"))
                binding.tvAction.text = "已过期"
                binding.ivGold.setImageResource(R.mipmap.icon_gold)
            } else {
                //
                if (item.receiveDay!! >= 16) {
                    // 可升级
                    binding.root.setBackgroundResource(R.drawable.shape_shop9000_state3)
                    binding.tvDays.setBackgroundColor(Color.parseColor("#FF82B8"))
                    binding.tvAction.setTextColor(Color.WHITE)
                    binding.ivGold.setImageResource(R.mipmap.icon_gold)
                    binding.tvAction.text = "领取"
                } else {
                    // 可领取
                    binding.root.setBackgroundResource(R.drawable.shape_shop9000_state3)
                    binding.tvDays.setBackgroundColor(Color.parseColor("#FF82B8"))
                    binding.tvAction.setTextColor(Color.WHITE)
                    binding.ivGold.setImageResource(R.mipmap.icon_gold)
                    binding.tvAction.text = "领取"
                }
            }


        }
    }
}